<template>
    <Layout style="background-color: white">
        <Modal title="检查任务" :transfer=false v-model="hasModel" :width=1200 @on-cancel="modelClose">
        <Form ref="dataForm" :model="dataForm" :label-width="100">
            <!--<Row>
                <Col span="24" style="font-size:16px;color:#464c5b;font-weight: bold">
                    <Divider orientation="left">检查任务信息</Divider>
                </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
                <Col span="11">
                    <FormItem label="任务名称:">
                        {{dataForm.taskName}}
                    </FormItem>
                </Col>
                <Col span="11">
                    <FormItem label="检查日期:">
                        {{dataForm.taskDate}}
                    </FormItem>
                </Col>
            </Row>
            <Row type="flex" justify="space-around" class="detail-background-clor">
                <Col span="11">
                    <FormItem label="检查单位:" prop="execOrgId">
                        {{dataForm.execOrgName}}
                    </FormItem>
                </Col>
                <Col span="11">
                    <FormItem label="检查人:" prop="execUserId">
                        {{dataForm.execUserName}}
                    </FormItem>
                </Col>
            </Row>
            <Row type="flex" justify="space-around" >
                <Col span="11">
                    <FormItem label="受检单位:" prop="checkedOrg">
                        {{dataForm.checkedOrgName}}
                    </FormItem>
                </Col>
                <Col span="11">
                    <FormItem label="参与人员:" prop="participant">
                        {{dataForm.participant}}
                        &lt;!&ndash;<Input type="text" v-model="dataForm.participant"/>&ndash;&gt;
                    </FormItem>
                </Col>
            </Row>
            <Row type="flex" justify="space-around" class="detail-background-clor">
                &lt;!&ndash; <Col span="11" >
                     <FormItem label="检查类型:">
                         {{dataForm.checkTypeName}}
                     </FormItem>
                 </Col>&ndash;&gt;
                <Col span="11">
                    <FormItem label="检查级别:" prop="checkLevel">
                        {{dataForm.checkLevelName}}
                    </FormItem>
                </Col>
                <Col span="11"></Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
                <Col span="23">
                    <FormItem label="检查任务描述:" prop="notes">
                        {{dataForm.notes}}
                        &lt;!&ndash;<Input v-model="dataForm.notes" type="textarea" :autosize="{minRows: 3,maxRows: 5}"/>&ndash;&gt;
                    </FormItem>
                </Col>
            </Row>-->
           <!-- <Row>
                <Col span="24" style="font-size:16px;color:#464c5b;font-weight: bold">
                    <Divider orientation="left">问题录入</Divider>
                </Col>
            </Row>-->
            <Row>
                <Col span="24">
                <Table  :loading="loading" highlight-row stripe size="small" :columns="pointColumns" :data="pointData" ></Table>
                </Col>
            </Row>
           <!-- <Row type="flex" justify="space-around" class="code-row-bg">
                <Col span="23">
                    <FormItem>
                        <Button v-if="editable" class='ivu-btn-save' :loading="buttonLoading" @click="saveData()">确定</Button>
                        <Button v-if="editable" class='ivu-btn-cancel' @click="modelClose"
                                style="margin-left: 2px">取消
                        </Button>
                        <Button v-else class='ivu-btn-save' @click="modelClose">关闭</Button>
                    </FormItem>
                </Col>
            </Row>-->
        </Form>
            <div slot="footer">
                <Button v-if="editable" class='ivu-btn-save' :loading="buttonLoading" @click="saveData()">确定</Button>
                <Button v-if="editable" class='ivu-btn-cancel' @click="modelClose"
                        style="margin-left: 2px">取消
                </Button>
                <Button v-else class='ivu-btn-save' @click="modelClose">关闭</Button>
            </div>
        </Modal>
        <cascaderOrg v-if="false"></cascaderOrg>
        <cascaderUser v-if="false"></cascaderUser>

        <Modal title="图片上传" :transfer=false footer-hide v-model="pictureModal" :width=600>
            <Form ref="dataForm" :label-width="100">
                <Row type="flex" justify="space-around" class="code-row-bg" style="margin-top: 10px">
                    <Col span="23">
                        <FormItem label="上传图片：">
                            <div class="demo-upload-list" v-for="item in uploadList" :key="item.id">
                                    <img :src="item.url">
                                    <div class="demo-upload-list-cover">
                                        <Icon type="ios-eye-outline" @click.native="handleView(item.name,item.url)"></Icon>
                                        <Icon type="ios-trash-outline" v-if="!editable"></Icon>
                                        <Icon type="ios-trash-outline" v-else @click.native="handleRemove(item)"></Icon>
                                    </div>
                            </div>
                            <Upload
                                    ref="upload"
                                    :show-upload-list="false"
                                    :default-file-list="defaultList"
                                    :format="['jpg','jpeg','png']"
                                    :max-size="1024"
                                    :on-format-error="handleFormatError"
                                    :on-exceeded-size="handleMaxSize"
                                    :before-upload="handleBeforeUpload"
                                    multiple
                                    type="drag"
                                    :action="upUrl"
                                    :disabled="!editable"
                                    style="display: inline-block;width:58px;">
                                <div style="width: 58px;height:58px;line-height: 58px;">
                                    <Icon type="ios-camera" size="20"></Icon>
                                </div>
                            </Upload>
                            <Modal title="View Image" v-model="visible">
                                <img :src="viewUrl" v-if="visible" style="width: 100%">
                                <div slot="footer">
                                    <Button type="primary" class='ivu-btn-save'  @click="visible=false">关闭</Button>
                                </div>
                            </Modal>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        </Modal>
    </layout>
</template>

<script>
    import {Api} from '../../../../api/index.js'
    import {sessionStorage} from '../../../../common/cacheUtils.js';
    import cascaderOrg from '../../../../components/cascader-org'
    import cascaderUser from '../../../../components/cascader-user'

    export default {
        components: {
            cascaderOrg,cascaderUser
        },
        props:{
            editable :{
                type : Boolean
            },
            mainTaskId :{
                type : String
            },
            hasModel:{
                type: Boolean,
                default: false
            },
        },
        data() {
            return {
                defaultList: [
                ],
                imgName: '',
                visible: false,
                fillItemId:'',
                uploadList: [],
                upUrl:Api.uploadPTWFiles,
                viewUrl : Api.downloadPTWSchemeFile,
                files :[],
                buttonLoading: false,pictureModal : false,
                form1: {},
                dataForm: {},
                //分页参数
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                selectRows:[],
                columns1: [
                    {
                        type: 'selection',
                        title: '序号',
                        width: 70,
                        align: 'center'
                    },
                    {
                        minWidth: 220,
                        title: '任务名称',
                        key: 'taskName',
                        align: 'center'
                    },
                    {
                        minWidth: 130,
                        title: '检查日期',
                        key: 'taskDate',
                        align: 'center'
                    },
                    {
                        minWidth: 130,
                        title: '检查单位',
                        key: 'execOrgName',
                        align: 'center'
                    },
                    {
                        minWidth: 130,
                        title: '受检单位',
                        key: 'checkedOrgName',
                        align: 'center'
                    },
                   /* {
                        minWidth: 120,
                        title: '检查类型',
                        align: 'center',
                        key: 'checkType',
                        render: (h, params) => {
                            if(params.row.checkType == '0'){
                                return h('span',{ },'日常检查')
                            }else if(params.row.checkType == '1'){
                                return h('span',{ },'监督检查')
                            }else if(params.row.checkType == '2'){
                                return h('span',{ },'体系审核')
                            }
                        }
                    },*/
                    {
                        minWidth: 135,
                        title: '检查级别',
                        key: 'checkLevel',
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.checkLevel == '0'){
                                return h('span',{ },'公司级')
                            }else if(params.row.checkLevel == '1'){
                                return h('span',{ },'二级单位级')
                            }else if(params.row.checkLevel == '2'){
                                return h('span',{ },'班组级')
                            }
                        }
                    },
                    {
                        minWidth: 130,
                        title: '任务来源',
                        key: 'taskSource',
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.taskStatus == '1'){
                                return h('span',{ },'计划任务')
                            }else if(params.row.taskStatus == '2'){
                                return h('span',{ },'临时任务')
                            }
                        }
                    },
                    {
                        minWidth: 130,
                        title: '任务状态',
                        key: 'taskStatus',
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.taskStatus == '1'){
                                return h('span',{ },'未执行')
                            }else if(params.row.taskStatus == '2'){
                                return h('span',{ },'执行中')
                            }else if(params.row.taskStatus == '3'){
                                return h('span',{ },'已执行')
                            }
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        minWidth: 120,
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.taskStatus == '1' || params.row.taskStatus == '2') {
                                return h('div', [
                                    h('a', {
                                        props: {
                                            type: 'md-eye',
                                            size: '20'
                                        },
                                        style: {
                                            marginRight: "0px"
                                        },
                                        on: {
                                            click: () => {
                                                this.toEdit(params,true);
                                            }
                                        }
                                    }, '执行')
                                ]);
                            }else {
                                return h('div', [
                                    h('a', {
                                        props: {
                                            type: 'md-eye',
                                            size: '20'
                                        },
                                        style: {
                                            marginRight: "0px"
                                        },
                                        on: {
                                            click: () => {
                                                this.viewData(params,false);
                                            }
                                        }
                                    }, '详情')
                                ]);
                            }
                        }
                    }
                ],
                dataTable: [],
                model1: false,
                tableHeight: '',
                pointData : [],
                pointColumns:[],
                currentUser : {},
                datas : [],
                fillItem : [],
                listData : {},
                imgItems : [],loading: false,
            }
        },
        mounted: function () {
           /* this.tableHeight = window.innerHeight - 220;
            this.currentUser = {
                label : JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserName"],
                value: JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"]
            }
            this.query();*/
        },
        methods: {
            modelClose(){
                this.$emit('closeModel');
            },
            handleView (name,url) {
                this.viewUrl = url;
                this.imgName = name;
                this.visible = true;
            },
            handleRemove (file) {
                //删除操作
                let _this = this;
                let config = {
                    title: '系统提示',
                    content: '确认删除图片吗?',
                    okText: '确定',
                    cancelText: '取消',
                    onOk: function () {

                        _this.$Spin.show({
                            render: (h) => {
                                return h('div', [
                                    h('Icon', {
                                        'class': 'demo-spin-icon-load',
                                        props: {
                                            type: 'ios-loading',
                                            size: 18
                                        }
                                    }),
                                    h('div', 'Loading')
                                ])
                            }
                        });
                        _this.uploadList.splice(_this.uploadList.indexOf(file), 1);

                        _this.$http.delete(Api.downloadPTWSchemeFile  + '/' + file.id).then((res) => {
                            _this.$Message.success('删除成功');
                            _this.uploadList = [];
                            _this.$http.get(_this.upUrl, {params: {}}).then((res) => {
                                if(res.data.data!=null){
                                    res.data.data.map((item)=>{
                                        _this.uploadList.push({ name : item.fileName, id : item.id , url : Api.downloadPTWSchemeFile + '/' + item.id});
                                    });
                                }
                                //this.downloadUrl = this.downloadUrl + '/' + res.data.id;
                            }).catch(e => {
                                console.log(e)
                                this.$Message.error("数据获取失败")
                            })

                            _this.$Spin.hide();
                        }).catch(e => {
                            _this.$Spin.hide();
                            _this.$Message.error('删除失败' + e);
                        })
                    },
                    onCancel: function () {
                    }
                }
                this.$Modal.confirm(config);
            },
            handleFormatError (file) {
                this.$Message.error('格式不正确, 请上传 jpg 或 png');
            },
            handleMaxSize (file) {
                this.$Message.error('图片不能大于1M.');
            },
            handleBeforeUpload (file) {

                if(file.size > 1024 * 1024){
                    this.$Message.error('图片不能大于1M.');
                    return false;
                }
                var index = file.name.lastIndexOf(".");
                var suffix = file.name.substr(index+1);

                if(suffix!='jpg' && suffix!='jpeg' && suffix!='png'){
                    this.$Message.error("请上传jpg,jpeg,png格式的图片");
                    return false;
                }

                const check = this.uploadList.length < 9;
                if (!check) {
                    this.$Message.error('最多上传9张图片');
                    return false;
                }

                let formData = new FormData();
                formData.append("files", file);
                this.$http.post(this.upUrl + '/picture', formData).then((res) => {
                    if (res.data.result == "success") {
                        this.$Message.success("保存成功");
                        // this.uploadList.push(file);
                        this.viewPicture({fillItemId:this.fillItemId},'fillItemId')
                    } else {
                        this.$Message.error("附件上传失败");
                    }
                }).catch(e => {
                    console.log(e);
                    this.$Message.error("数据获取失败");
                })

                return false;
            },
            viewPicture(row ,id){
                this.fillItemId=row[id]
                this.upUrl = Api.uploadPTWFiles + '/' + row[id] + '/files';
                this.pictureModal = true;
                //根据reportFile查询附件
                this.uploadList = [];
                this.$http.get(this.upUrl, {params: {}}).then((res) => {
                    if(res.data.data!=null){
                        res.data.data.map((item)=>{
                            this.uploadList.push({ name : item.fileName, id : item.id , url : Api.downloadPTWSchemeFile + '/' + item.id});
                        });
                    }
                    //this.downloadUrl = this.downloadUrl + '/' + res.data.id;
                }).catch(e => {
                    console.log(e)
                    this.$Message.error("数据获取失败")
                })
            },
            uuidGenerator() {
                let   originStr = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
                let   originChar = '0123456789abcdef';
                let   len = originChar.length;
                return originStr.replace(/x/g, function(match) {
                    return originChar.charAt(Math.floor(Math.random() * len))
                })

            },

            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },

            toEdit(params) {
                this.dataForm = {};
                this.pointData = [];
                this.datas = [];
                this.pointColumns = [];
                this.imgItems = [];

                let url = Api.getCheckModelByTaskId + '/' + this.mainTaskId;
                let data = {
                    userId: JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"],
                    orgId : JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createOrgId"]
                };
                this.$http.get(url, {params : data}).then((res) => {

                    this.model1 = true;
                    this.dataForm = res.data.instanceMap;

                    //采集项
                    this.fillItem =  res.data.fillItem;
                    //获取采集项的属性
                    res.data.fillItem.forEach((item)=>{
                        this.listData[item.fillItemId] = '';
                    })

                    //列表项
                    this.findAllItem(res.data.listItem);
                    //console.log(this.datas);

                    //列表项最大深度
                    let maxDeep = 0;
                    this.datas.forEach((item,index)=>{
                        let obj = {};
                        //获取列表项所有父级的name依次展示在table里
                        let names = item.itemName.split('|&|');
                        // let writeDesc = item.writeDesc&&item.writeDesc.split('|&|');
                        for(let i = 0; i<names.length ; i++){
                            obj['listName' + i] = names[i];
                            // obj['writeDesc' + i] = writeDesc==null||writeDesc[i]==null?'':writeDesc[i];
                        }

                        let tempMaxDeep = names.length;
                        if(tempMaxDeep > maxDeep){
                            maxDeep = tempMaxDeep;
                        }
                        obj.listItemId = item.listItemId;
                        Object.assign(obj, this.listData);
                        this.pointData.push(obj);
                    })


                    //列表项表头
                    for(let i = 0; i <maxDeep; i++ ){
                        let tableTitle = {};
                        tableTitle = {
                            minWidth: 150,
                            title: '检查项目',
                            key: 'listName' + i,
                            align: 'left',tooltip:true
                        };
                        this.pointColumns.push(tableTitle);
                        // let tableTitle1 = {};
                        // tableTitle1 = {
                        //     minWidth: 150,
                        //     title: '检查内容',
                        //     key: 'writeDesc' + i,
                        //     align: 'left',tooltip:true
                        // };
                        // this.pointColumns.push(tableTitle1);
                    }

                    //处理table组件的表头
                    this.fillItem.forEach((item)=>{
                        //类型不为拍照都按文本处理
                        let tableTitle = {};
                        //采集项表头
                        //1000001013000000005 拍照型
                        //1000001013000000004 数值型
                        //1000001013000000002 文本型
                        //1000001013000000006 单选型

                        if(item.dataType == '1000001013000000005' ){
                            //所有的图片类型的fillItemId 记录在 imgItems里
                            this.imgItems.push(item.fillItemId)
                            tableTitle = {
                                width: 80,
                                title: '照片',
                                key: 'img',
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h("Icon", {
                                        props: {
                                            type: 'md-eye',
                                            size: '20'
                                        },
                                        style: {
                                            marginRight: "0px"
                                        },
                                        on: {
                                            click: () => {
                                                this.viewPicture(row,item.fillItemId);
                                            }
                                        }
                                    });
                                }
                            };
                        }else if(item.dataType == '1000001013000000006' ){
                            tableTitle = {
                                width: 300,
                                title: item.itemName,
                                key: item.fillItemId,
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h('RadioGroup',{
                                            props:{
                                                value: row[item.fillItemId],
                                            },
                                            on:{
                                                'on-change':(val)=>{
                                                    (this.pointData[index])[item.fillItemId] = val;
                                                }
                                            }
                                        },[
                                            h('Radio',{
                                                props:{
                                                    label: '1'
                                                }
                                            },'符合'),
                                            h('Radio',{
                                                props:{
                                                    label: '0'
                                                }
                                            },'不符合')
                                        ]
                                    );

                                }
                            };

                        }else{
                            tableTitle = {
                                width: 300,
                                title: item.itemName,
                                key: item.fillItemId,
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h("Input", {
                                        props: {
                                            value: row[item.fillItemId],
                                        },
                                        on: {
                                            input: val => {
                                                (this.pointData[index])[item.fillItemId] = val;
                                            },
                                        }
                                    });
                                }
                            };
                        }
                        this.pointColumns.push(tableTitle);
                    })

                    console.log(res.data);
                    //把listInstance中的值，赋值给this.pointData
                    this.pointData.forEach((item)=>{
                        let keys = Object.keys(item);
                        for(let i = 0;i < keys.length;i++){
                            for(let j = 0; j < res.data.listInstance.length;j++){
                                if(keys[i] ==   res.data.listInstance[j].fillItemId && item.listItemId == res.data.listInstance[j].listItemId ){
                                    item[keys[i]] = res.data.listInstance[j].fillData;
                                }
                            }
                        }
                    });
                    // this.imgItems 图片类型如果第一次查询没有存值，则默认赋予一个UUID
                    this.pointData.forEach((item)=>{
                        let keys = Object.keys(item);
                        for(let i = 0;i < keys.length;i++){
                            for(let j=0;j<this.imgItems.length;j++){
                                if(keys[i] ==  this.imgItems[j] && (item[keys[i]] == '' || item[keys[i]] == null || item[keys[i]] == undefined) ){
                                    item[keys[i]] = this.uuidGenerator();
                                }
                            }
                        }
                    });

                  /*  this.pointData.forEach((item,index)=>{
                        item.currentUserId = item.reportUserId;
                        item.currentUserName = item.reportUserName;
                        item.currentOrgId = item.existOrgId;
                        item.currentOrgName = item.existOrgName;
                    });*/

                }).catch(e => {
                    this.$Message.error('请求失败' + e);
                })
            },

            findAllItem(listItem){
                listItem.forEach((item,index)=>{
                    if(item.childItem!=null && item.childItem!=undefined){
                        if(item.childItem.length > 0){
                            this.findAllItem(item.childItem);
                        }else{
                            this.datas.push(item);
                        }
                    }else{
                        this.datas.push(item);
                    }
                })
            },

            viewData(params) {
                this.dataForm = {};
                this.pointData = [];
                this.datas = [];
                this.pointColumns = [];
                this.imgItems = [];

                let url = Api.getCheckModelByTaskId + '/' + this.mainTaskId;
                let data = {
                    userId: JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"],
                    orgId : JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createOrgId"]
                };
                this.$http.get(url, {params : data}).then((res) => {

                    this.model1 = true;
                    this.dataForm = res.data.instanceMap;

                    //采集项
                    this.fillItem =  res.data.fillItem;
                    //获取采集项的属性
                    res.data.fillItem.forEach((item)=>{
                        this.listData[item.fillItemId] = '';
                    })

                    //列表项
                    this.findAllItem(res.data.listItem);
                    //console.log(this.datas);

                    //列表项最大深度
                    let maxDeep = 0;
                    this.datas.forEach((item,index)=>{
                        let obj = {};
                        //获取列表项所有父级的name依次展示在table里
                        let names = item.itemName.split('|&|');
                        // let writeDesc = item.writeDesc&&item.writeDesc.split('|&|');
                        for(let i = 0; i<names.length ; i++){
                            obj['listName' + i] = names[i];
                            // obj['writeDesc' + i] = writeDesc==null||writeDesc[i]==null?'':writeDesc[i];
                        }

                        let tempMaxDeep = names.length;
                        if(tempMaxDeep > maxDeep){
                            maxDeep = tempMaxDeep;
                        }
                        obj.listItemId = item.listItemId;
                        Object.assign(obj, this.listData);
                        this.pointData.push(obj);
                    })


                    //列表项表头
                    for(let i = 0; i <maxDeep; i++ ){
                        let tableTitle = {};
                        tableTitle = {
                            minWidth: 150,
                            title: '检查项目',
                            key: 'listName' + i,
                            align: 'left',tooltip:true
                        };
                        this.pointColumns.push(tableTitle);

                        // let tableTitle1 = {};
                        // tableTitle1 = {
                        //     minWidth: 150,
                        //     title: '检查内容',
                        //     key: 'writeDesc' + i,
                        //     align: 'left',tooltip:true
                        // };
                        // this.pointColumns.push(tableTitle1);
                    }

                    //处理table组件的表头
                    this.fillItem.forEach((item)=>{
                        //类型不为拍照都按文本处理
                        let tableTitle = {};
                        //采集项表头
                        //1000001013000000005 拍照型
                        //1000001013000000004 数值型
                        //1000001013000000002 文本型

                        if(item.dataType == '1000001013000000005' ){
                            //所有的图片类型的fillItemId 记录在 imgItems里
                            this.imgItems.push(item.fillItemId)
                            tableTitle = {
                                width: 80,
                                title: '照片',
                                key: 'img',
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h("Icon", {
                                        props: {
                                            type: 'md-eye',
                                            size: '20'
                                        },
                                        style: {
                                            marginRight: "0px"
                                        },
                                        on: {
                                            click: () => {
                                                this.viewPicture(row,item.fillItemId);
                                            }
                                        }
                                    });
                                }
                            };
                        }else if(item.dataType == '1000001013000000006' ){
                            tableTitle = {
                                width: 300,
                                title: item.itemName,
                                key: item.fillItemId,
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h('RadioGroup',{
                                            props:{
                                                value: row[item.fillItemId],
                                            },
                                            on:{
                                                'on-change':(val)=>{
                                                    (this.pointData[index])[item.fillItemId] = val;
                                                }
                                            }
                                        },[
                                            h('Radio',{
                                                props:{
                                                    label: '1'
                                                }
                                            },'符合'),
                                            h('Radio',{
                                                props:{
                                                    label: '0'
                                                }
                                            },'不符合')
                                        ]
                                    );

                                }
                            };

                        }else{
                            tableTitle = {
                                width: 300,
                                title: item.itemName,
                                key: item.fillItemId,
                                align: 'center',
                                render: (h, { row, index }) => {
                                    return h("Input", {
                                        props: {
                                            value: row[item.fillItemId],
                                        },
                                        on: {
                                            input: val => {
                                                (this.pointData[index])[item.fillItemId] = val;
                                            },
                                        }
                                    });
                                }
                            };
                        }
                        this.pointColumns.push(tableTitle);
                    })

                    console.log(res.data);
                    //把listInstance中的值，赋值给this.pointData
                    this.pointData.forEach((item)=>{
                        let keys = Object.keys(item);
                        for(let i = 0;i < keys.length;i++){
                            for(let j = 0; j < res.data.listInstance.length;j++){
                                if(keys[i] ==   res.data.listInstance[j].fillItemId && item.listItemId == res.data.listInstance[j].listItemId ){
                                    item[keys[i]] = res.data.listInstance[j].fillData;
                                }
                            }
                        }
                    });
                    // this.imgItems 图片类型如果第一次查询没有存值，则默认赋予一个UUID
                    this.pointData.forEach((item)=>{
                        let keys = Object.keys(item);
                        for(let i = 0;i < keys.length;i++){
                            for(let j=0;j<this.imgItems.length;j++){
                                if(keys[i] ==  this.imgItems[j] && (item[keys[i]] == '' || item[keys[i]] == null || item[keys[i]] == undefined) ){
                                    item[keys[i]] = this.uuidGenerator();
                                }
                            }
                        }
                    });

                    /*  this.pointData.forEach((item,index)=>{
                          item.currentUserId = item.reportUserId;
                          item.currentUserName = item.reportUserName;
                          item.currentOrgId = item.existOrgId;
                          item.currentOrgName = item.existOrgName;
                      });*/

                }).catch(e => {
                    this.$Message.error('请求失败' + e);
                })
            },
            saveData() {
                debugger
                this.buttonLoading=true
                let subForm = {};
                let listInstance = [];
                subForm.instanceMap = this.dataForm;
                console.log( this.pointData)
                this.pointData.forEach((item)=>{
                    //获取所有采集项ID
                    this.fillItem.forEach((fileItem)=>{
                        let keys = Object.keys(item);
                        for(let i = 0;i < keys.length;i++){
                            if(keys[i] ==   fileItem.fillItemId ){
                                let obj = {};
                                obj.listItemId = item.listItemId;
                                obj.fillItemId = keys[i];
                                obj.fillData = item[keys[i]];
                                listInstance.push(obj);
                            }
                        }
                    })
                });
                subForm.listInstance = listInstance;
                //console.log(subForm)
                this.$http.post(Api.saveCheckModel,  subForm ).then((res) => {
                    this.$Message.success("保存成功")
                    /*this.model1 = false;
                    this.query();*/
                    this.$emit('closeModel');
                    this.$emit('query'); this.buttonLoading=false
                }).catch(e => {
                   /* this.model1 = false;
                    this.query();*/
                    this.$emit('closeModel');
                    this.$emit('query'); this.buttonLoading=false
                    this.$Message.error("数据保存失败")
                })
            },
            query() {
                let data = {
                    currentPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    userId: JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"]
                }

                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));

                let url = Api.getSecurityCheckTaskList;
                this.$http.get(url, {params: data}).then((res) => {
                    this.dataTable = res.data.data;
                    this.pagedata.total = res.data.totalSize;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            reset() {
                this.form1 = {};
                this.query();
            },
            getSelectRows (rows){
                this.selectRows = rows;
            },
            toSubmit(){
                let selectRows =  this.selectRows;
                if(selectRows.length == 0 || selectRows.length >1){
                    this.$Message.info('请选择一条数据！');
                    return;
                }
                let mainTaskId = selectRows[0].mainTaskId;
                let taskCheckLineId = selectRows[0].taskCheckLineId;
                let taskCheckPointId =  selectRows[0].taskCheckPointId;
                let userId = '';
                let orgId = '';

                if(selectRows[0].taskStatus != '3'){
                    this.$Message.warning('已执行的任务不可提交,请确认！');
                    return;
                }else{
                    //checker = JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"];
                }
                let _this= this;
                let config={
                    title:'系统提示',
                    content:'确认提交选中数据吗?',
                    okText:'确定',
                    cancelText:'取消',
                    onOk:function(){
                        _this.$Spin.show({
                            render: (h) => {
                                return h('div', [
                                    h('Icon', {
                                        'class': 'demo-spin-icon-load',
                                        props: {
                                            type: 'ios-loading',
                                            size: 18
                                        }
                                    }),
                                    h('div', 'Loading')
                                ])
                            }
                        });
                        let url = Api.securityCheckSubmitTask;
                        this.$http.get(url, {params: {}}).then((res) => {
                            if (res.data.result == "success") {
                                _this.$Message.success('风险识别提交成功!');
                                _this.query();
                                _this.$Spin.hide();
                            } else {
                                this.$Message.error("风险识别提交失败！");
                            }

                        }).catch(e => {
                            _this.$Spin.hide();
                            _this.$Message.error('风险识别提交失败' + e);
                        })
                    },
                    onCancel:function(){
                    }
                }
                this.$Modal.confirm(config);
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
        },
    }
</script>
<style lang='css'>
    .demo-upload-list{
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0,0,0,.2);
        margin-right: 4px;
    }
    .demo-upload-list img{
        width: 100%;
        height: 100%;
    }
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .demo-upload-list:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
</style>
